package com.sam.spring.chapter2;

import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.sam.spring.chapter1.helloworld.HelloAPI;
import com.sam.spring.chapter2.bean.Printer;

public class MethodInjectTest {
	@Test
	public void testLookup() {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
				"chapter2/lookupMethodInject.xml");
		System.out.println("=====singleton sayHello=======");
		HelloAPI helloAPI1 = context.getBean("helloAPI1", HelloAPI.class);
		helloAPI1.sayHello();
		helloAPI1 = context.getBean("helloAPI1", HelloAPI.class);
		helloAPI1.sayHello();

		System.out.println("=====prototype sayHello=======");
		HelloAPI helloAPI2 = context.getBean("helloAPI2", HelloAPI.class);
		helloAPI2.sayHello();
		helloAPI2 = context.getBean("helloAPI2", HelloAPI.class);
		helloAPI2.sayHello();
	}

	@Test
	public void testMethodReplacer() {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
				"chapter2/methodReplacerInject.xml");
		Printer printer = context.getBean("printer", Printer.class);
		printer.print("我将被替换");
	}
}
